package com.smbms.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.druid.stat.TableStat.Mode;
import com.smbms.entity.SmbmsBill;
import com.smbms.entity.page.Page;
import com.smbms.service.BillService;
import com.smbms.service.ProviderService;

@Controller
@RequestMapping("/bill")
public class BillController {

	
	@Autowired
	BillService billService;
	
	@Autowired
	ProviderService providerService;

	@RequiresPermissions("bill_list")
	@RequestMapping("/list")
	public String list(String queryProductName,
			Integer queryProviderId,
			@RequestParam(value = "queryIsPayment", required = false, defaultValue = "0") Integer queryIsPayment,
			@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, 
			Model model){
		
		
		Page<SmbmsBill> pageInfo = billService.selectByPage(queryProductName, queryProviderId, queryIsPayment, pageNo);
		
		pageInfo.getMapCond().put("queryProductName", queryProductName==null?"":queryProductName);
		pageInfo.getMapCond().put("queryProviderId", queryProviderId==null?0:queryProviderId);
		pageInfo.getMapCond().put("queryIsPayment", queryIsPayment);
		
		model.addAttribute("pageInfo", pageInfo);
		model.addAttribute("providerList", providerService.selectProviders());
		return "billlist";
	}
}
